package zjump.simplelibrary.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class PlatformUtils {

	public static final int NET_WORK_DISCONNE = 0x0;

	public static final int NET_WORK_MOBILE = 0x1;

	public static final int NET_WORK_WIFI = 0x2;

	public static final int getNetworkStatus(Context context) {
		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);

		if (isConnect(connectivityManager, ConnectivityManager.TYPE_WIFI)) {
			return NET_WORK_WIFI;
		}

		if (isConnect(connectivityManager, ConnectivityManager.TYPE_MOBILE)) {
			return NET_WORK_MOBILE;
		}

		return NET_WORK_DISCONNE;
	}

	private static boolean isConnect(ConnectivityManager connectivityManager, int networkType) {
		NetworkInfo networkInfo = connectivityManager.getNetworkInfo(networkType);
		if (networkInfo != null && networkInfo.isConnected()) {
			return true;
		}
		return false;
	}

}
